<template>
    <div class="recommend-box">
        <el-row class="recommend-row" v-for="(item, index) in items" :key="index" tag="div" @click="detail(item)">
            <el-col :span="12">
                <el-image class="recommend-img" :src="item.cover" fit="cover">
                    <template #error>
                        <div class="image-slot" style="font-size: 30px;">
                            <el-icon>
                                <Picture />
                            </el-icon>
                        </div>
                    </template>
                </el-image>
            </el-col>
            <el-col :span="12">
                <el-row>
                    <h5 class="recommend-top">
                        热销推荐
                    </h5>
                </el-row>
                <el-row>
                    <el-col :span="12" class="recommend-side">
                        <h5 class="recommend-left-h5">
                            {{ item.name }}
                        </h5>
                    </el-col>
                    <el-col :span="12" class="recommend-side">
                        <el-row>
                            <el-text class="recommend-price">
                                <span style="font-size: 32px;">￥</span>{{ (item.price).toFixed(1) }}
                            </el-text>
                        </el-row>
                    </el-col>
                </el-row>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import axios from 'axios';
import { ElMessage } from 'element-plus';
import { utilMethods } from '../util/methods';

axios.defaults.baseURL = '/api'


export default {
    data() {
        return {
            items: [
                // {
                //     name: "草莓蛋糕",
                //     cover: "img7.jpg",
                //     image1: "",
                //     image2: "",
                //     price: 89,
                //     intro: "商品描述",
                //     stock: 80
                // },
                // {
                //     name: "草莓蛋糕",
                //     cover: 'img7.jpg',
                //     gTag: "数码产品",
                //     price: 100.0,

                // },
                // {
                //     name: "芝士蛋糕",
                //     cover: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
                //     gTag: "数码产品",
                //     price: 100.0
                // },
                // {
                //     name: "",
                //     cover: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
                //     gTag: "数码产品",
                //     price: 100.0
                // },
            ]
        }
    },
    created() {
        this.getRecommend();
    },
    methods: {
        detail(goods) {
            utilMethods.detail(goods);
        },
        getRecommend() {
            axios.get('/recommend/goodsList')
                .then(result => {
                    if (result.data.code === 1) {
                        console.log(result.data.data);
                        this.items = result.data.data;
                    }
                })
                .catch(err => {
                    console.log(err);
                    if (err.response.status === 500) {
                        ElMessage.error("无法连接后端服务器");
                    }
                })
        }
    }
}
</script>

<style>
.recommend-box {
    margin: 50px auto;
    width: 1000px;
    position: relative;
    overflow: hidden;
}

.recommend-row {
    margin: 20px 0 100px 0;
    border: 10px lightgray solid;
    border-radius: 10px;
    box-sizing: content-box;
}

.recommend-top {
    font: 700 48px/100px 微软雅黑;
    width: 100%;
    min-height: 100px;
    height: 100px;
    color: white;
    background-color: var(--el-color-warning-light-3);
    margin: 0 auto;
    text-align: center;
}

.recommend-side {
    width: 100%;
    min-height: 400px;
    height: 400px;
    background-color: var(--el-color-warning-light-3);
    color: white;
}

.recommend-left-h5 {
    font: 700 48px 微软雅黑;
    writing-mode: vertical-rl;
    margin: 0 auto;
    padding-top: 25%;
    letter-spacing: 0.3em;
}

.recommend-img {
    width: 500px;
    height: 500px;
}


.recommend-price {
    font: 700 45px 微软雅黑;
    margin: 0 auto;
    margin-top: 150px;
    letter-spacing: 0.1em;
}
</style>